package cn.luoshaocheng.system.service.impl;

import cn.luoshaocheng.basic.service.impl.BaseServiceImpl;

import cn.luoshaocheng.system.domain.Role;

import cn.luoshaocheng.system.mapper.RoleMapper;
import cn.luoshaocheng.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
        @Autowired
        private RoleMapper roleMapper;

    @Override
    public void deleteById(Long id) {
        //删除中间表：t_role_permission
        roleMapper.removeRolePermissionByRoldId(id);
        //删除中间表：t_role_menu
        roleMapper.removeRoleMenuByRoldId(id);
        //删除角色
        roleMapper.delete(id);
    }

    @Override
    public List<Role> deptTree() {

        return null;
    }

    @Override
    public void add(Role role) {
        roleMapper.save(role);
        roleMapper.saveRolePermission(role.getId(),role.getPermissions());
        roleMapper.saveRoleMenu(role.getId(),role.getMenus());
    }
}

